<?php
namespace App\Demo\Http\Tal;

use App\Demo\Database\Entities\Demo;
use Doctrine\ORM\Query;
use Fendx\Annotation\Scanner;
use Fendx\Cache;
use Fendx\Db;
use Fendx\Annotation\Controller;
use Fendx\Annotation\RequestMapping;
use Fendx\Exception\BizException;
use Fendx\Exception\ErrCode;
use Fendx\Request;
use Fendx\Response;
use Symfony\Component\Finder\Finder;

/**
 * Class Index
 * 首页
 * @author gary
 *
 * @Controller(prefix="index", options={"dddCOM"})
 */
class Index
{

    /**
     * 初始化模板
     *
     * @RequestMapping(path="/index", methods={"get", "post"}, options={"ff", "eee"})
     */
    public function index(Request $request, Response $response)
    {

        $em = Db::getWEntityManager();
        $repo0 = $em->getRepository(Demo::class);
        /* @var $entity Demo */
        $entity = $repo0->getDataList([], null, 10, 10);
        var_export($entity);

        return [
            $entity,
            __DIR__
        ];
        //throw new BizException('ffff');
       // ErrCode::throws('001', '0001');
//        $finder = new Finder();
//        $files = $finder->files()->in(APP_PATH . '*' . FD_DS . 'Config' . FD_DS)->name('Routers.php');
//        foreach ($files as $file) {
//            var_dump($file);
//        }

        $ret = Cache::factory(Cache::CACHE_TYPE_MEMCACHE, 'default')->getObj()->getAllKeys();
        var_dump($ret);
        echo "this is test";
        // \Fendx\Logger::info("write an single file", 'dd', ['ddd' => 'fff']);
        //ErrCode::throws(001, 002, []);

        $em = Db::getWEntityManager();
        $repo0 = $em->getRepository(Demo::class);
        /* @var $entity Demo */
        $entity = $repo0->findAll();
        var_export($entity);

//        $db = Read::Factory('ams_company_ext');
//        $ret = $db->getById(1);
//        var_dump($ret);
        //$entity->setShareTitle('ffff3333');

        //$em->flush();
        // var_dump($em->flush());

    /*    $em = EmRead::getEntityManager();
        $read = EmRead::getRepository(AmsCompanyExt::class);
        /* @var $ret AmsCompanyExt */
        //$ret = $read->getListByCondition([1, 2]);*/
        return [4515415];

        $entityManager = \Fendx\Db\EntityManager::Factory('r', 'default');
        $entityManager = $entityManager->getEntityManager();
 /*       $isDevMode = true;
        $proxyDir = null;
        $cache = null;
        $useSimpleAnnotationReader = false;
        $config = Setup::createAnnotationMetadataConfiguration(array(DATABASE_PATH . 'Entities'), $isDevMode, $proxyDir, $cache, $useSimpleAnnotationReader);
// or if you prefer yaml or XML
//$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode);
//$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/config/yaml"), $isDevMode);

// database configuration parameters
        $conn = array(
            'driver' => 'pdo_mysql',
            'host' => 'rm-2ze47437qm7id95qkwo.mysql.rds.aliyuncs.com',
            'port' => 3306,
            'user' => 'damai_w',
            'password' => '7dCdJthcZXjiLsEKV128tCa2KkGpKjVQ',
            'dbname' => 'sandbox-damai',
        );

// obtaining the entity manager
        $entityManager = EntityManager::create($conn, $config);*/

        /* @var $repo AmsCompanyExtRepo */
        $repo = $entityManager->getRepository(AmsCompanyExt::class);

        $ret = $repo->findBy(['id' => [1,2]]);
        //$ret = $entityManager->createQuery('select * from ams_company_ext')->getResult();
        //var_dump($ret);
//        $repo = $entityManager->getRepository(AmsCompanyExt::class);
//        var_dump($repo);
//        var_dump($repo->findAll());
        return [time()];
    }

    public function pubabc() {

    }

    private function prmet() {}

    protected function protemethod() {}
}
